package com.qf.lanzhou.blog.api.controller.login;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.service.InitPasswordSuccessAuditService;
import com.qf.lanzhou.blog.api.service.impl.login.InitPasswordSuccessAuditServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author LEON-HE
 */
@WebServlet("/successAudit.do")
public class SuccessAudit extends BaseServletPost {
    private InitPasswordSuccessAuditService service = new InitPasswordSuccessAuditServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String auditId = req.getParameter("auditId");
        Long id = Long.decode(auditId);
        System.out.println("开始处理通过事务，事务ID："+auditId);
        try{
            service.processAudit(id);
            successResultWrite(null,resp);
            System.out.println("处理事务"+id+"完成");
        }catch (RuntimeException e){
            String errorMsg = e.getMessage();
            failedResultWrite(errorMsg,resp);
            System.out.println("处理事务"+id+"失败");
        }
    }
}
